<?php

namespace app\admin\model;
use think\Model;
use fast\Tree;

class Slider extends Model
{
    // 表名
    public $name = 'slider';
    public $prefix_new = 'fa_';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    public $data;


    public function getTypeTextAttr($value, $data)
    {
        $s=array();
        $content=array(
            "1"=>"右到左滑动",
            "2"=>"上到下滑动",
            );
                if($value) {
            $nn=preg_split("/,/",$value);
        }else{
            $nn=array();
        }
        for($i=0;$i<count($nn);$i++) {
            if($nn[$i]=="") continue;
            if(isset($content[$nn[$i]])) $s[]= $content[$nn[$i]];
        }
        return join(",",$s);
    }

    function getimages($arr){
        $result=array();
        foreach($arr as $k=>$v) {
            $result[] = $v['src'];
        }
        return $result;
    }

    // 状态列表
    public function getStatusList()
    {
        return ['0' => '失效', '1' => '正常'];
    }
    
    // 获取状态文本
    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    function getimagesfield($arr){
        $result=array();
        foreach($arr as $k=>$v) {
            $temp=array();
            $temp['title'] = $v['title'];
            $temp['href'] = $v['href'];
            $temp['url'] = $v['src'];
            $result[]=$temp;
        }
        return json_encode($result);
    }
}